<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 基本表单</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="__PUBLIC__/admin/favicon.ico"> <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">

</head>
<include file="Admin@Index:cache" />
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">

            <div class="col-sm-6" style="width:50%;left:25%">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>添加权限</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">上级权限</label>
                                <div class="col-sm-8">
                                    <select class="form-control m-b" name="account" id="pid" >
                                        <option></option>
                                        <foreach name="list" item="list">
                                        <option value="<{$list.id}>"><?php echo str_repeat('--',($list['level']-1)*2);?><if condition="$list['level'] neq '1'">→</if><{$list.name}></option>
                                        </foreach>>

                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label" >权限名称：</label>

                                <div class="col-sm-8">
                                    <input type="text" id="power_name" placeholder="权限名称" class="form-control">
                                    <!--<span class="help-block m-b-none">请输入您注册时所填的E-mail</span>-->
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">控制器或方法名：</label>
                                <div class="col-sm-8">
                                    <input type="text" id="actionname" placeholder="控制器或方法名" class="form-control">
                                </div>
                            </div>


                            <div class="form-group">
                                <div class="col-sm-offset-3 col-sm-8">
                                    <button class="btn btn-sm btn-info" type="submit" id="sub">添 加</button>
                                </div>
                            </div>
                            <!--<div class="form-group">-->
                                <!--<label class="col-sm-2 control-label">*商品标题图片</label>-->
                                <!--<div class="col-sm-10">-->
                                    <!--<div class="btn-file">-->
                                        <!--<label for="uploadimg" class="btn btn-primary" >上传图片</label>-->
                                        <!--<input id="uploadimg" onchange="upload()" style="display:none" type="file" name="uploadimg" >-->
                                        <!--<input id="title_img" type="hidden" name="title_img" >-->
                                        <!--&lt;!&ndash;<span class="help-block m-b-none">请上传图片大小为400*400px</span>&ndash;&gt;-->
                                    <!--</div>-->
                                    <!--<div  class="product_img" id="img">-->
                                        <!--<img  src="__PUBLIC__/admin/img/webuploader.png" style="height:150px;width: 150px">-->
                                    <!--</div>-->
                                <!--</div>-->
                            <!--</div>-->
                        </form>
                    </div>
                </div>
            </div>
        </div>


    </div>



    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="__PUBLIC__/admin/js/content.js?v=1.0.0"></script>
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/ajaxfileupload.js"></script>
    <script>
        //注意：id名如果和onchange函数名相同的话，将会报错。
        function upload(){
            var tourl='__MODULE__/Power/uploadimg';
            $.ajaxFileUpload({
                url:tourl,//需要链接到服务器地址
                secureuri:false,
                fileElementId:'uploadimg',//文件选择框的id属性file的id
                dataType:'json',
                success:function(data){
                console.log(data);
                    if(data.code=='1001'){
                        var html='<img  style="width:15rem" src="'+data.result+'" />';
                        $('#img').html(html);
                        $('#title_img').val(data.result);
                    }else{
                        if(data.status=='0'){
                            layer.alert(data.info);
                        }else{
                            layer.alert(data.result);
                        }
                    }
                }
            });
        }
    </script>
    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
         $('#sub').on('click',function(){
             var pid=$('#pid').val();
             var name=$('#power_name').val();
             var actionname=$('#actionname').val();
             if(name==''){
                 layer.alert('权限名不能为空');
                 return false;
             }
             if(actionname==''){
                 layer.alert('方法名不能为空');
                 return false;
             }
             layer.load(2);
             $.post('__MODULE__/Power/add_power',{pid:pid,name:name,actionname:actionname},function(data){
                 layer.closeAll('loading');
                 if(data.code=='1001'){
                     window.location.reload();
                 }else{
                     if(data.status=='0'){
                         layer.alert(data.info);
                     }else{
                         layer.alert(data.result);
                     }
                 }
             });
         });
    </script>

    
    

</body>

</html>
